<?php

class module {

	var $zam;

	function main()
	{
		switch ($this->zam->data['get']['app'])
		{
			default:
			case 'basicinfo':
				$this->edit_profile();
				break;
			case 'basic':
				$this->basic();
				break;
			case 'about':
				$this->about();
				break;
			case 'settings':
				$this->settings();
				break;
		}
	}
	
	function edit_profile()
	{
		$this->zam->skin->set_vars( array(
			'title'		=>	'Edit Profile',
			'head'		=>	$this->zam->tags->stylesheet('panel.css') . $this->zam->tags->script('prototype.js') . $this->zam->tags->script('panel.js'),
			'content'	=>	"\t<div id=\"panel\">\n\t\t<a href=\"javascript:void(0);\" onclick=\"loadPanel();\"><img src=\"{$this->zam->url}_images/loadpanel.gif\" alt=\"Loading\" /></a>\n\t</div>\n"
		) );
		
		$this->zam->skin->display('template.tpl');
	}
	
	function basic()
	{
		$where = "member_id = " . intval($this->zam->sess->user['id']);
		
		if ( !$this->zam->data['post']['change'] )
		{
			# Profile data
			$result = $this->zam->sql->construct( array(
				'action'	=>	'select',
				'db'		=>	constant('DB_EXTRA'),
				'where'		=>	$where,
				'limit'		=>	1
			) );
			
			$data = $this->zam->sql->fetch();
			
			$this->zam->skin->set_vars( array(
				'sex'			=>	$data['sex'],
				'relationship'	=>	$data['relationship'],
				'location'		=>	$data['location'],
				'occupation'	=>	$data['occupation'],
				'politics'		=>	$data['political'],
				'religion'		=>	$data['religion']
			) );
			
			$this->zam->skin->display('basicpanel.tpl');
		}
		else
		{
			$this->edit_profile();
			
			$set = array(
				'sex'			=>	$this->zam->data['post']['sex'],
				'relationship'	=>	$this->zam->data['post']['relationship'],
				'location'		=>	$this->zam->data['post']['location'],
				'occupation'	=>	$this->zam->data['post']['occupation'],
				'political'		=>	$this->zam->data['post']['politics'],
				'religion'		=>	$this->zam->data['post']['religion']
			);
			
			# Update profile
			$this->zam->sql->construct( array(
				'action'	=>	'update',
				'db'		=>	constant('DB_EXTRA'),
				'set'		=>	$set,
				'where'		=>	$where,
				'limit'		=>	1
			) );
		}
	}
	
	function about()
	{
		$this->zam->skin->display('aboutpanel.tpl');
	}
	
	function settings()
	{
		$this->zam->skin->display('settingspanel.tpl');
	}
	
}

?>